#!/bin/bash
# $1 is the path to a mnt.sh script
echo "$0 - BEGIN"

# Determine the server and share on which to operate.
echo "parameter = $1"
#MNTPATH=$(readlink -f $1)
MNTPATH=$1
echo "A MNTPATH = $MNTPATH"
MNTPATH=${MNTPATH%/*}
echo "B MNTPATH = $MNTPATH"
SHARE=${MNTPATH##*/}
echo "SHARE = $SHARE"
MNTPATH=${MNTPATH%/*}
echo "C MNTPATH = $MNTPATH"
SERVER=${MNTPATH##*/}
echo "SERVER = $SERVER"

# Mount the share.
if [ -x $HOME/mnt/$SERVER/$SHARE/smbh-mount-this ]; then
  echo "mounting $SERVER/$SHARE"
  MOUNTCMD="mount -t smbfs -o credentials=$HOME/.smbcredentials //$SERVER/$SHARE $HOME/mnt/$SERVER/$SHARE"
  echo "MOUNTCMD = $MOUNTCMD" 
  if [ "X$KDE_FULL_SESSION" = "Xtrue" ]; then
    echo "kdesudo"
    kdesudo -c "$MOUNTCMD" 
  else
    echo "sudo"
    sudo $MOUNTCMD
  fi
fi

echo "$0 - END"
exit 0
